package com.ctgu.controller;

import com.ctgu.entity.Orders;
import com.ctgu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("order")
public class OrdersController {

    @Autowired
    private OrderService orderService;

    //查询已登录用户的订单
    @RequestMapping("OrderList")
    public String order(int user_id, Model model){

        List<Orders> orderList = orderService.findAll(user_id);
        model.addAttribute("orderList",orderList);
        return "orderList";
    }
    //删除订单记录，并返回订单页
    @RequestMapping("deleteOrder")
    public  String deleteOrder(int id, HttpServletRequest request){
        orderService.deleteOrderById(id);
        int id1 =(int)request.getSession().getAttribute("user_id");
        return "redirect:OrderList?user_id="+id1 ;
    }

}

